<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    用户名:<input type="text" name="name">
    <p id="pp"></p>
    <script>
        var name2 = document.getElementsByTagName('input')[0];
        var pp = document.getElementById('pp');
        name2.onblur = function(){
            var xhr = new XMLHttpRequest();
            xhr.open('get','2.php?name='+name2.value,true);
            xhr.send(null);
            xhr.onreadystatechange = function(){
                if(this.readyState == 4){
                    if(this.responseText == 1){
                         pp.innerHTML = '该用户名已经被注册';
                    }else{
                        pp.innerHTML = '可以注册';
                    }
                }
            }
        }
    </script>
</body>
</html>